import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import set_node_cls from '@feidao/web/atom/browser/ui/set-node-cls';

import P01 from './P01';
import P02 from './P02';
import P03 from './P03';

export default async function a002(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// 列表查询
	const criteria: any = { exam_room_state: '未编排' };
	// 获取输入框的内容
	const exam_data = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="exam_data"]').value;
	if (exam_data) {
		criteria['exam_data'] = new Date(exam_data).getTime();
	}
	const time_quantum_type = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="time_quantum_type"]').value;
	if (time_quantum_type) {
		criteria['time_quantum_type'] = time_quantum_type;
	}
	const teaching_building = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="teaching_building"]').value;
	if (teaching_building) {
		criteria['teaching_building'] = { $regex: '.*' + teaching_building + '.*', $options: 'i' };
	}
	const belong_area = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="belong_area"]').value;
	if (belong_area) {
		criteria['belong_area'] = { $regex: '.*' + belong_area + '.*', $options: 'i' };
	}
	const floor_no = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="floor_no"]').value;
	if (floor_no) {
		criteria['floor_no'] = floor_no;
	}
	const data = await nodejs(fd.data.spaceid, 'exam_room_date_find', { criteria, page_size: 10, page_no: 1 });
	const p = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P02"]');
	if (data.count === 0) {
		// 默认不筛选数据
		set_node_cls(p, 'display-n', false);
	} else {
		set_node_cls(p, 'display-n', true);
	}
	render(fd, data.dataArray, P01, 'P01', 'inner');

	const fy = fd.data.node.querySelector('[data-feidao-id="fy"]');
	fy.setAttribute('total', data.count);
}
